﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Umbraco.Core.Models.Entities;

namespace DDD.StorageModel.Model
{
    public class Test1Context:DbContext
    {
        public Test1Context(DbContextOptions<Test1Context> options) : base(options)
        {

        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            var Assembly = this.GetType().Assembly;
            var Types = Assembly.GetTypes().Where(m => m.FullName != null//筛选那种cs文件
                                                   && typeof(BaseEntity).IsAssignableFrom(m)//跟EntityBase有关系的
                                                   && !m.IsAbstract//类型不能是抽象的
                                                   && m.Name != "BaseEntity").ToArray();//不能是EntityBase的
            foreach (var entityType in Types)
            {
                modelBuilder.Entity(entityType);
            }
            modelBuilder.ApplyConfigurationsFromAssembly(Assembly);
            base.OnModelCreating(modelBuilder);
        }
    }
}
